import base from '@/config/baseUrl';
import store from "@/store";
import { judgeLogin } from '@/config/login';
//import pako from '@/common/pako.js'
export default {
getExtStoreId(type){
	try{
		const extConfig = uni.getExtConfigSync ? uni.getExtConfigSync() : {bid:1}
		return extConfig[type];
	}catch(err){
		console.log(err,'getExtStoreId__error')
	}
},
	/**
	 * 跳转再封装，不支持复杂传参。
	 */
	goJump(path, params = {},auth=null,switchTab='to') {
		//navigateTo to   redirectTo redirect  switchTab  tab  reLaunch  launch   navigateBack  back
		//console.log('switchTab',switchTab)
		let objParams = params;
		// 是否跳转外部链接
		if (~path.indexOf('http')) {
			// #ifdef H5
			window.location = path;
			// #endif
			// #ifndef  H5
			// router.push({
			// 	path: '/pages/public/webview',
			// 	query: {
			// 		'webviewPath': path
			// 	}
			// })
			// #endif
			return false
		}
		// 判断是否有参数
		if (path.indexOf('?') !== -1) {
			let index = path.lastIndexOf('?');
			let query = path.substring(index + 1, path.length);
			let arr = query.split('&')
			path = path.slice(0, index);
			arr.forEach(item => {
				let mArr = []
				let obj = {}
				mArr = item.split('=');
				obj[mArr[0]] = mArr[1];
				objParams = {
					...objParams,
					...obj
				}

			})
		}
		if (switchTab===null||switchTab==='')switchTab='to'
		//console.log('auth',auth)
		
		if (auth===''||auth===false||auth===1||auth===null){
			uni.$u.route({url: path,params:objParams,type:switchTab})
		}else{
			judgeLogin(() => {
				uni.$u.route({url: path,params:objParams,type:switchTab})
			});
		}

	},

	/**提示框
	 *title(标题)
	 *icon(图标):  success，loading，none
	 *duration(延时): 0为不关闭, 毫秒数
	 *options(其它参数)
	 */
    msg(title, duration=2000, mask=false, icon='none'){
    	//统一提示方便全局修改
    	if(Boolean(title) === false){
    		return;
    	}
    	uni.showToast({
    		title,
    		duration,
    		mask,
    		icon
    	});
    },
getQueryString(url, name) {
  var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i')
  var r = url.substr(1).match(reg)
  if (r != null) {
    return r[2]
  }
  return null;
},
	param(data) {
		console.log(data);
	  let url = ''
	  for (var k in data) {
	    let value = data[k] !== undefined ? data[k] : ''
	    url += '&' + k + '=' + encodeURIComponent(value)
	  }
	  return url ? url.substring(1) : ''
	},

	// 年月日，时分秒
	// "YYYY-mm-dd HH:MM"
	dateFormat(fmt, timestamp) {
		let date = new Date(timestamp * 1000); //根据时间戳生成的时间对象
		let ret;
		const opt = {
			"Y+": date.getFullYear().toString(), // 年
			"m+": (date.getMonth() + 1).toString(), // 月
			"d+": date.getDate().toString(), // 日
			"H+": date.getHours().toString(), // 时
			"M+": date.getMinutes().toString(), // 分
			"S+": date.getSeconds().toString() // 秒
			// 有其他格式化字符需求可以继续添加，必须转化成字符串
		};
		for (let k in opt) {
			ret = new RegExp("(" + k + ")").exec(fmt);
			if (ret) {
				fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
			};
		};
		return fmt;
	},

}
